import { Pipe, PipeTransform } from '@angular/core';
import { ToolService } from '../service/tool.service';

@Pipe({
  name: 'substr'
})
export class SubstrPipe implements PipeTransform {
  /**
   * @param value 
   * @param args  参数为数组[start,length]
   */
  transform(value: any, args?: any): any {
    let val=""+value;
    if(ToolService.isStringJSON(args)){
       let param= JSON.parse(args);
       if(param.length==1){
          return val.substr(param[0]);
       }
       return val.substr(param[0],param[1]);
    }else{
      return value;
    }
    
  }

}
